package pa165.dominatingspecies.service.converter;

import java.util.ArrayList;
import java.util.List;

import pa165.dominating.species.entities.Element;
import pa165.dominating.species.enums.ElementType;
import static pa165.dominating.species.enums.ElementType.BUSH;
import static pa165.dominating.species.enums.ElementType.EVERGREEN;
import static pa165.dominating.species.enums.ElementType.GRASS;
import static pa165.dominating.species.enums.ElementType.JUNGLE_TREE;
import static pa165.dominating.species.enums.ElementType.MUD;
import static pa165.dominating.species.enums.ElementType.PEBBLESTONE;
import static pa165.dominating.species.enums.ElementType.SALT_WATER;
import static pa165.dominating.species.enums.ElementType.SAND;
import static pa165.dominating.species.enums.ElementType.SNOW;
import static pa165.dominating.species.enums.ElementType.SOIL;
import static pa165.dominating.species.enums.ElementType.STONE;
import static pa165.dominating.species.enums.ElementType.TREE;
import static pa165.dominating.species.enums.ElementType.WATER;
import pa165.dominating.species.tos.ElementTo;

/**
 *
 * @author Ondrej Prazak
 */
public class ElementConverter {

    public Element convertElementTo2Element(ElementTo elementTo) {
        if (elementTo == null) {
            return null;
        }
        Element ele = new Element();
        ele.setId(elementTo.getId());
        ele.setDescription(elementTo.getDescription());
        ele.setType((elementTo.getType()));

        return ele;
    }

    public ElementTo convertElement2ElementTo(Element element) {
        if (element == null) {
            return null;
        }
        ElementTo to = new ElementTo();
        to.setId(element.getId());
        to.setDescription(element.getDescription());
        to.setType((element.getType()));

        return to;
    }

    public List<ElementTo> convert2ElementTo(List<Element> elements) {
        final List<ElementTo> elementTos = new ArrayList<>();
        for (Element element : elements) {
            elementTos.add(convertElement2ElementTo(element));
        }
        return elementTos;
    }

    public List<Element> convert2Element(List<ElementTo> elementTos) {
        final List<Element> elements = new ArrayList<>();
        for (ElementTo elementTo : elementTos) {
            elements.add(convertElementTo2Element(elementTo));
        }
        return elements;
    }

    public ElementType string2Enum(String selected) {
        if (selected == null) {
            return null;
        }
        ElementType converted = null;
        switch (selected) {
            case "water":
                converted = ElementType.WATER;
                break;
            case "salt water":
                converted = ElementType.SALT_WATER;
                break;
            case "mud":
                converted = ElementType.MUD;
                break;
            case "sand":
                converted = ElementType.SAND;
                break;
            case "pebblestone":
                converted = ElementType.PEBBLESTONE;
                break;
            case "soil":
                converted = ElementType.SOIL;
                break;
            case "stone":
                converted = ElementType.STONE;
                break;
            case "grass":
                converted = ElementType.GRASS;
                break;
            case "bush":
                converted = ElementType.BUSH;
                break;
            case "evergreen":
                converted = ElementType.EVERGREEN;
                break;
            case "tree":
                converted = ElementType.TREE;
                break;
            case "jungle tree":
                converted = ElementType.JUNGLE_TREE;
                break;
            case "snow":
                converted = ElementType.SNOW;
                break;

        }
        return converted;
    }

    public String enum2String(ElementType selected) {
        if (selected == null) {
            return "";
        }
        String converted = null;
        switch (selected) {
            case WATER:
                converted = "water";
                break;
            case SALT_WATER:
                converted = "salt water";
                break;
            case MUD:
                converted = "mud";
                break;
            case SAND:
                converted = "sand";
                break;
            case PEBBLESTONE:
                converted = "pebblestone";
                break;
            case SOIL:
                converted = "soil";
                break;
            case STONE:
                converted = "stone";
                break;
            case GRASS:
                converted = "grass";
                break;
            case BUSH:
                converted = "bush";
                break;
            case EVERGREEN:
                converted = "evergreen";
                break;
            case TREE:
                converted = "tree";
                break;
            case JUNGLE_TREE:
                converted = "jungle tree";
                break;
            case SNOW:
                converted = "snow";
                break;

        }
        return converted;
    }
}
